﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Elite
{
    class Ship
    {
        public string Name { get; set; }

        /// <summary>
        /// %
        /// </summary>
        public double C02FilterEfficiency { get; set; }

        /// <summary>
        /// %
        /// </summary>
        public double ToiletEfficiency { get; set; }

        /// <summary>
        /// t * m3
        /// </summary>
        public double PayLoadCapacity { get; set; }

        /// <summary>
        /// t * m3
        /// </summary>
        public double DrinkableWaterCharge { get; set; }

        /// <summary>
        /// t * m3
        /// </summary>
        public double FoodCharge { get; set; }

        /// <summary>
        /// t * m3
        /// </summary>
        public double AirBatteriesCharge { get; set; }

        /// <summary>
        /// t * m3
        /// </summary>
        public double FretCharge { get; set; }

        /// <summary>
        /// calculé. en t.m3
        /// </summary>
        public double FreeSpace
        {
            get
            {
                return this.PayLoadCapacity - this.DrinkableWaterCharge - this.FoodCharge - this.FretCharge - this.AirBatteriesCharge;
            }
        }

        public string Serialize()
        {
            return
                "Information                            |Valeur          " + "\n\r" +
                "---------------------------------------|----------------" + "\n\r" +
                " => Capacitié totale de charge utile   |" + this.PayLoadCapacity + " t.m3" + "\n\r" +
                "---------------------------------------|----------------" + "\n\r" +
                " => Stockage de produits vitaux        |" + "\n\r" +
                "   - Eau potable                       |" + this.DrinkableWaterCharge + " t.m3 (" + this.WaterDaysLeft + " j restants)" + "\n\r" +
                "   - Nourriture                        |" + this.FoodCharge + " t.m3 (" + this.FoodDaysLeft + " j restants)" + "\n\r" +
                "   - Batterie d'air comprimé           |" + this.AirBatteriesCharge + " t.m3 (" + this.AirDaysLeft + " j restants)" + "\n\r" +
                "---------------------------------------|----------------" + "\n\r" +
                " => Espace dédié au fret               |" + "\n\r" +
                "   - Aucun produit n'est stocké.       |" + "\n\r" +
                "   - Espace libre                      |" + this.FreeSpace + " t.m3" + "\n\r" +
                "---------------------------------------|----------------" + "\n\r" +
                " => Fonctionnement des systèmes vitaux |" + "\n\r" + 
                "   - Traitement du CO2                 |" + this.C02FilterEfficiency + " %" + "\n\r" +
                "   - Traitement des urines et selles   |" + this.ToiletEfficiency + " %" + "\n\r" +
                "---------------------------------------|----------------";
        }

        public Ship()
        {
            this.PayLoadCapacity = 100;
            this.DrinkableWaterCharge = 1;
            this.FoodCharge = 1;
            this.FretCharge = 0;
            this.AirBatteriesCharge = 1;
            this.ToiletEfficiency = 100;
            this.C02FilterEfficiency = 100;
        }

        /// <summary>
        /// Conso quotidienne d'air : 0.835 kg
        /// </summary>
        public int AirDaysLeft
        {
            get
            {
                return Convert.ToInt32(Math.Truncate(this.AirBatteriesCharge * 1000 / 0.835));
            }
        }

        /// <summary>
        /// Conso quotidienne de nourriture : 0.617 kg
        /// </summary>
        public int FoodDaysLeft
        {
            get
            {
                return Convert.ToInt32(Math.Truncate(this.FoodCharge * 1000 / 0.617));
            }
        }

        /// <summary>
        /// Conso quotidienne d'eau : 3.909 kg
        /// </summary>
        public int WaterDaysLeft
        {
            get
            {
                return Convert.ToInt32(Math.Truncate(this.DrinkableWaterCharge * 1000 / 3.909));
            }
        }

    }
}
